﻿/***************************************************
//  Copyright (c) Premium Tax Free 2011
***************************************************/

using System;
using System.Diagnostics;
using System.Text;

namespace PremierTaxFree.PTFLib.Extensions
{
    public static class SystemEx
    {
        public static bool ToBool(this Enum en)
        {
            return Convert.ToBoolean(Convert.ToInt32(en));
        }

        public static T ToValue<T>(this Enum en, params T[] arr)
        {
            int value = Convert.ToInt32(en);
            Debug.Assert(arr.Length > value);
            return arr[value];
        }

        public static bool InRange<T>(this T value, T min, T max) where T : IComparable
        {
            return min.CompareTo(value) <= 0 && value.CompareTo(max) <= 0;
        }

        public static string Random(this string @any, int length)
        {
            byte[] buffer = new byte[length];

            Random rnd = new Random(DateTime.Now.Millisecond);
            rnd.NextBytes(buffer);
            return UnicodeEncoding.Unicode.GetString(buffer);
        }
    }
}
